t = int(input())
for _ in range(t):
n,m = map(int,input().split())
arr=[]
for i in range(n):
arr.append(list(map(int,input().split())))
for rI in range(n):
for cI in range(m):
item=arr[rI][cI]
if rI == 0:
up=0
else:
up=arr[rI-1][cI]
if rI == n-1:
down=0
else:
down=arr[rI+1][cI]
if cI == 0:
left=0
else:
left=arr[rI][cI-1]
if cI == m-1:
right=0
else:
right= arr[rI][cI+1]
if up < item and down < item and left < item and right < item :
arr[rI][cI]=max(up , down , left, right)
for row in arr:
for num in row:
print(num,end=" ")
print()
4A - Watermelon | 476A - Dreamoon and Stairs |
1409A - Yet Another Two Integers Problem | 977A - Wrong Subtraction |
263A - Beautiful Matrix | 180C - Letter |
151A - Soft Drinking | 1352A - Sum of Round Numbers |
281A - Word Capitalization | 1646A - Square Counting |
266A - Stones on the Table | 61A - Ultra-Fast Mathematician |
148A - Insomnia cure | 1650A - Deletions of Two Adjacent Letters |
1512A - Spy Detected | 282A - Bit++ |
69A - Young Physicist | 1651A - Playoff |
734A - Anton and Danik | 1300B - Assigning to Classes |
1647A - Madoka and Math Dad | 710A - King Moves |
1131A - Sea Battle | 118A - String Task |
236A - Boy or Girl | 271A - Beautiful Year |
520B - Two Buttons | 231A - Team |
479C - Exams | 1030A - In Search of an Easy Problem |